package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashMap;

public class Configuration {

	private String connStr;

	public String getConnStr() {
		return connStr;
	}

	private static HashMap<String, Configuration> map;

	public static Configuration getConfig(String key) {
		return getConfig(key, false);
	}

	public static Configuration getConfig(String key, boolean forceRefresh) {
		if (!forceRefresh && map.containsKey(key)) {
			return map.get(key);
		}
		Configuration c = new Configuration();
		c.read(key);

		return c;
	}

	private void read(String key) {
		try {
			BufferedReader f = new BufferedReader(new FileReader(new File(key)));
			String line = "";
			while ((line = f.readLine()) != null) {
				String[] s = line.split("=");
				if (s[0].equalsIgnoreCase("connstr")) {
					this.connStr = s[1];
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
